package com.lpy.book.config;


import com.lpy.book.model.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

// 统一异常处理
@Slf4j
@ResponseBody
@ControllerAdvice
public class ErrorHandler {

    // 捕获异常
    @ExceptionHandler
    public Result handler(Exception e) {
        // 返回统一结果
        return Result.fail("内部发生错误");
    }

    @ExceptionHandler
    public Result handler(NullPointerException e) {
        return Result.fail("空指针异常");
    }

}
